package vesion2.tank;


import com.fasterxml.jackson.annotation.JsonIgnore;
import vesion2.barrier.spec.BornPlace;
import vesion2.main.ObjectManager;
import vesion2.object.Point;
import vesion2.tool.Timer1;

public class MyTank extends BaseTank{
    private int maxBullets;
    @JsonIgnore
    private int capacity;
    //控制移动速度
    @JsonIgnore
    private Timer1 timer2=new Timer1(100);

    private BornPlace place;

    public MyTank(){
        this(new Point(),5);
    }
    public MyTank(Point left_up,int maxBullets) {
       this(left_up,0,maxBullets);
    }

    public MyTank(Point left_up, int maxBullets, ObjectManager manager){
        super(left_up,0,manager);
        this.maxBullets=maxBullets;
        capacity=maxBullets;
    }

    public MyTank(Point left_up, int ort,int maxBullets) {
        super(left_up, ort);
        this.maxBullets=maxBullets;
        capacity=maxBullets;
    }


    public int getMaxBullets() {
        return maxBullets;
    }

    public void setMaxBullets(int maxBullets) {
        this.maxBullets = maxBullets;
        capacity=maxBullets;
    }

    public BornPlace getPlace() {
        return place;
    }

    public void setPlace(BornPlace place) {
        this.place = place;
    }

    public synchronized boolean increaseCapacity() {
        if(capacity<maxBullets)
            ++capacity;
        else
            return false;
        return true;
    }
    public synchronized boolean decrementCapacity(){
        if(capacity>0)
            --capacity;
        else
            return false;
        return true;
    }

    @Override
    public void shitBullet() {
        if(timer1.isOverOne()&&decrementCapacity()) {
            Bullet bullet = new Bullet(this);
            manager.addBullet(bullet);
            bullet.start();
            timer1.Start();
        }
    }

    @Override
    public void setAlive(boolean alive) {
        super.setAlive(alive);
        if(!alive) {
            timer2.End();
            manager.incDNUm();
        }
        else {
            setOrt(0);
            left_up=place.getTankPoint();
        }
    }

    @Override
    public boolean move() {
        boolean re=false;
        if(timer2.isOverOneAndStar()) {
           re= super.move();
        }
        return re;
    }

    @Override
    public String toString() {
        return "MyTank{" +
                "left_up=" + left_up +
                ", ort=" + ort +
                ", maxBullets=" + maxBullets +
                ", capacity=" + capacity +
                ", place=" + place +
                '}';
    }
}
